{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Length of the Longest Alphabetical Continuous Substring"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Medium"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: longestContinuousSubstring"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #最长的字母序连续子字符串的长度"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p><strong>字母序连续字符串</strong> 是由字母表中连续字母组成的字符串。换句话说，字符串 <code>\"abcdefghijklmnopqrstuvwxyz\"</code> 的任意子字符串都是 <strong>字母序连续字符串</strong> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>例如，<code>\"abc\"</code> 是一个字母序连续字符串，而 <code>\"acb\"</code> 和 <code>\"za\"</code> 不是。</li>\n",
    "</ul>\n",
    "\n",
    "<p>给你一个仅由小写英文字母组成的字符串 <code>s</code> ，返回其 <strong>最长</strong> 的 字母序连续子字符串 的长度。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"abacaba\"\n",
    "<strong>输出：</strong>2\n",
    "<strong>解释：</strong>共有 4 个不同的字母序连续子字符串 \"a\"、\"b\"、\"c\" 和 \"ab\" 。\n",
    "\"ab\" 是最长的字母序连续子字符串。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>s = \"abcde\"\n",
    "<strong>输出：</strong>5\n",
    "<strong>解释：</strong>\"abcde\" 是最长的字母序连续子字符串。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>\n",
    "\t<li><code>s</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [length-of-the-longest-alphabetical-continuous-substring](https://leetcode.cn/problems/length-of-the-longest-alphabetical-continuous-substring/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [length-of-the-longest-alphabetical-continuous-substring](https://leetcode.cn/problems/length-of-the-longest-alphabetical-continuous-substring/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"abacaba\"', '\"abcde\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        last=1\n",
    "\n",
    "        ans=1\n",
    "        for i in range(1, n):\n",
    "            cur=1\n",
    "            if ord(s[i-1])+1==ord(s[i]):\n",
    "                cur=last+1\n",
    "                ans=max(ans, cur)\n",
    "            \n",
    "            last=cur\n",
    "\n",
    "        return ans\n",
    "        \n",
    "\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        ans = 0\n",
    "        while i < n:\n",
    "            j = i + 1\n",
    "            while j < n and ord(s[j]) - ord(s[j - 1]) == 1:\n",
    "                j += 1\n",
    "            ans = max(ans, j - i)\n",
    "            i = j\n",
    "        return ans\n",
    "            \n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "            c = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "            d = {}\n",
    "            for i in range(len(c)):\n",
    "                d[c[i]] = i\n",
    "            Max = 0\n",
    "            Res = 1\n",
    "            left = 0\n",
    "            right = 1\n",
    "            while right < len(s):\n",
    "                if d[s[right]] - d[s[right - 1]] == 1:\n",
    "                    Max = right - left + 1\n",
    "                    Res = max(Max, Res)\n",
    "                    right += 1\n",
    "                else:\n",
    "                    Max = right - left\n",
    "                    Res = max(Max,Res)\n",
    "\n",
    "                    left = right\n",
    "                    right += 1\n",
    "\n",
    "            return Res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        def func(s):\n",
    "            n = len(s)\n",
    "            length = 1\n",
    "\n",
    "            tmp = 1\n",
    "            for i in range(1,n):\n",
    "                if ord(s[i])-ord(s[i-1])==1:\n",
    "                    tmp +=1\n",
    "                else:\n",
    "                    tmp =1\n",
    "                length = max(length,tmp)\n",
    "\n",
    "            return length\n",
    "        \n",
    "        return func(s)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        length = len(s)\n",
    "        if length <= 1:\n",
    "            return length\n",
    "\n",
    "        res = 0\n",
    "\n",
    "        tmp = 1\n",
    "        for i in range(1, length):\n",
    "            if ord(s[i]) == ord(s[i - 1]) + 1:\n",
    "                tmp += 1\n",
    "            else:\n",
    "                res = max(res, tmp)\n",
    "                tmp = 1\n",
    "\n",
    "        return max(res, tmp)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans=1\n",
    "        start=0\n",
    "        n=len(s)\n",
    "        for i in range(1,n):\n",
    "            if ord(s[i])-ord(s[i-1])!=1:\n",
    "                ans=max(ans,i-start)\n",
    "                start=i\n",
    "        return max(ans,n-start)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        maxlen, cnt = 1, 1\n",
    "        pre = s[:1]\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i])-ord(pre) == 1:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                cnt = 1\n",
    "            pre = s[i]\n",
    "            maxlen = max(maxlen, cnt)\n",
    "        return maxlen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = 1\n",
    "        i = 1\n",
    "        n = len(s)\n",
    "        while i < n:\n",
    "            if ord(s[i]) == ord(s[i-1]) + 1:\n",
    "                j = i - 1\n",
    "                while i < n and ord(s[i]) == ord(s[i-1]) + 1:\n",
    "                    i += 1\n",
    "                ans = max(ans, i - j)\n",
    "            else:\n",
    "                i += 1       \n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "\n",
    "        n = len(s)\n",
    "        ans = start = 0\n",
    "        for i in range(n):\n",
    "            if ord(s[i]) != ord(s[i-1])+1:\n",
    "                ans = max(ans, i-start)\n",
    "                start = i \n",
    "        return max(ans, n-start)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        pre = s[0]\n",
    "        res = 1\n",
    "        cnt = 1\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i]) - ord(pre) == 1:\n",
    "                cnt += 1\n",
    "                res = max(res,cnt)\n",
    "                pre = s[i]\n",
    "            else:\n",
    "                pre = s[i]\n",
    "                cnt = 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l,r = 0,1\n",
    "        res = 0\n",
    "        while r < len(s):\n",
    "            if ord(s[r]) == ord(s[r-1]) +1:\n",
    "                r += 1\n",
    "            else:\n",
    "                res = max(res, r -l)\n",
    "                l = r \n",
    "                r = r +1 \n",
    "        res = max(res, r-l)\n",
    "        print(l,r)\n",
    "        return res "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        num = 1\n",
    "        max_num = 1\n",
    "        if len(s) <= 1:\n",
    "            return 1\n",
    "        for i in range(len(s) - 1):\n",
    "            if ord(s[i]) + 1 != ord(s[i + 1]):\n",
    "                num = 1\n",
    "                #break\n",
    "            else:\n",
    "                num += 1\n",
    "                max_num = max(num, max_num)\n",
    "        #if ord(s[-1]) - 1 == ord(s[-2]):\n",
    "            #max_num += 1\n",
    "        return max_num\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        temp = res = 1\n",
    "        cur = ord(s[0])\n",
    "        for c in s[1:]:\n",
    "            cur += 1\n",
    "            if ord(c) == cur:\n",
    "                temp += 1\n",
    "                if temp == 26:\n",
    "                    return 26\n",
    "                res = max(res, temp)\n",
    "            else:\n",
    "                cur = ord(c)\n",
    "                temp = 1\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l =temp= 1\n",
    "        i = 0\n",
    "        while i<len(s)-1:\n",
    "            if  ord(s[i+1])-ord('a')== ord(s[i])+1-ord('a'):\n",
    "                temp+=1\n",
    "                l=max(l,temp)\n",
    "            else:\n",
    "                temp = 1\n",
    "            i+=1\n",
    "        return l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        temp = res = 1\n",
    "        cur = ord(s[0])\n",
    "        for c in s[1:]:\n",
    "            cur += 1\n",
    "            if ord(c) == cur:\n",
    "                temp += 1\n",
    "                if temp == 26:\n",
    "                    return 26\n",
    "                res = max(res, temp)\n",
    "            else:\n",
    "                cur = ord(c)\n",
    "                temp = 1\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = 1\n",
    "        n = len(s)\n",
    "        cur_len = 1\n",
    "        for i in range(1, n):\n",
    "            if ord(s[i]) - ord(s[i - 1]) == 1:\n",
    "                cur_len += 1\n",
    "            else:\n",
    "                cur_len = 1\n",
    "            ans = max(ans, cur_len)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        temp = res = 1\n",
    "        cur = ord(s[0])\n",
    "        for c in s[1:]:\n",
    "            cur += 1\n",
    "            if ord(c) == cur:\n",
    "                temp += 1\n",
    "                if temp == 26:\n",
    "                    return 26\n",
    "                res = max(res, temp)\n",
    "            else:\n",
    "                cur = ord(c)\n",
    "                temp = 1\n",
    "\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "        return max(ans, len(s) - start)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans,k,tmp=1,1,s[0]\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i]) == ord(tmp)+1:\n",
    "                k+=1\n",
    "            else:\n",
    "                k=1\n",
    "            tmp=s[i]\n",
    "            ans=max(ans,k)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        x = 0 \n",
    "        y = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) - ord(s[i-1]) == 1:\n",
    "                y += 1\n",
    "            else:\n",
    "                x = max(x, y)\n",
    "                y = 1\n",
    "        return max(x, y)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        order = \"abcdefghijklmnopqrstuvwxyza\"\n",
    "        nexts = {order[i]: order[i+1] for i in range(26)}\n",
    "        max_length = curr_length = 0\n",
    "        expect = \"a\"\n",
    "        for c in s:\n",
    "            if expect == \"a\" or c != expect:\n",
    "                max_length = max(max_length, curr_length)\n",
    "                curr_length = 0\n",
    "            expect = nexts[c]\n",
    "            curr_length += 1\n",
    "        max_length = max(max_length, curr_length)\n",
    "        return max_length"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l =temp= 1\n",
    "        i = 0\n",
    "        while i<len(s)-1:\n",
    "            if  ord(s[i+1])-ord('a')== ord(s[i])+1-ord('a'):\n",
    "                temp+=1\n",
    "                l=max(l,temp)\n",
    "            else:\n",
    "                temp = 1\n",
    "            i+=1\n",
    "        return l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        substring = \"\"\n",
    "        ans = 0\n",
    "        for ch in s:\n",
    "            if not substring or ord(ch) == ord(substring[-1]) + 1:\n",
    "                substring += ch\n",
    "            else:\n",
    "                ans = max(ans, len(substring))\n",
    "                substring = ch\n",
    "        return max(ans, len(substring))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "        return max(ans, len(s) - start)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        resultcount = 1\n",
    "        tempcount = 1\n",
    "        for index in range(len(s) - 1):\n",
    "            if ord(s[index]) + 1 == ord(s[index + 1]):\n",
    "                tempcount += 1\n",
    "            else:\n",
    "                if tempcount > resultcount:\n",
    "                    resultcount = tempcount\n",
    "                tempcount = 1\n",
    "        if tempcount > resultcount:\n",
    "            resultcount = tempcount\n",
    "        return resultcount"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        if not s: # 如果字符串为空，直接返回0\n",
    "            return 0\n",
    "        \n",
    "        # 初始化最长连续子字符串的长度和当前连续子字符串的长度\n",
    "        longest = 1\n",
    "        current_length = 1\n",
    "        \n",
    "        # 遍历字符串\n",
    "        for i in range(1, len(s)):\n",
    "            # 如果当前字符是上一个字符的后续字符\n",
    "            if ord(s[i]) == ord(s[i-1]) + 1:\n",
    "                current_length += 1\n",
    "                longest = max(longest, current_length)\n",
    "            else:\n",
    "                current_length = 1\n",
    "        \n",
    "        return longest\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        left=right=0\n",
    "        ant=1\n",
    "        while right<len(s)-1:\n",
    "            if ord(s[right+1])-ord(s[right])==1:\n",
    "                right+=1\n",
    "            else:\n",
    "                ant=max(ant,right-left+1)\n",
    "                left=right=right+1\n",
    "        \n",
    "        ant=max(ant,right-left+1)\n",
    "        return ant\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        res = 0\n",
    "        start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                res = max(res, i - start)\n",
    "                start = i\n",
    "        return max(res, len(s) - start)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "\n",
    "        ans = start = 0\n",
    "\n",
    "        for i in range(1, len(s)):\n",
    "\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "\n",
    "                ans = max(ans, i - start)\n",
    "\n",
    "                start = i  # 新起点\n",
    "\n",
    "        return max(ans, len(s) - start)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l =temp= 1\n",
    "        i = 0\n",
    "        while i<len(s)-1:\n",
    "            if  ord(s[i+1])== ord(s[i])+1:\n",
    "                temp+=1\n",
    "                l=max(l,temp)\n",
    "            else:\n",
    "                temp = 1\n",
    "            i+=1\n",
    "        return l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i-1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i\n",
    "        return max(ans, len(s) - start)\n",
    "\n",
    "\n",
    "\n",
    "        # substring = \"\"\n",
    "        # ans = 0\n",
    "        # for ch in s:\n",
    "        #     if not substring or ord(ch) == ord(substring[-1]) + 1:\n",
    "        #         substring += ch\n",
    "        #     else:\n",
    "        #         ans = max(ans, len(substring))\n",
    "        #         substring = ch\n",
    "        # return max(ans, len(substring))\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l, r = 0, 1\n",
    "        while r < len(s):\n",
    "            if not all(ord(s[i+1])-ord(s[i])==1 for i in range(l,r)):\n",
    "                l += 1\n",
    "            r += 1\n",
    "        return r-l\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l =temp= 1\n",
    "        i = 0\n",
    "        while i<len(s)-1:\n",
    "            if  ord(s[i+1])-ord('a')== ord(s[i])+1-ord('a'):\n",
    "                temp+=1\n",
    "                l=max(l,temp)\n",
    "            else:\n",
    "                temp = 1\n",
    "            i+=1\n",
    "        return l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        x = 0 \n",
    "        y = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) - ord(s[i-1]) != 1:\n",
    "                x = max(x, i-y)\n",
    "                y = i\n",
    "        return max(x, len(s)-y)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        cnt = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                cnt = max(cnt, i - start)\n",
    "                start = i\n",
    "        return max(cnt, len(s) - start)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans,temp=1,1\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i])-ord(s[i-1])==1:\n",
    "                temp+=1\n",
    "            else:\n",
    "                ans=max(ans,temp)\n",
    "                temp=1\n",
    "        return max(ans,temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        left=0\n",
    "        ant=1\n",
    "        for right in range(1,len(s)):\n",
    "    \n",
    "            if not ord(s[right])-ord(s[right-1])==1:\n",
    "                ant=max(ant,right-left)\n",
    "                left=right\n",
    "        ant=max(ant,len(s)-left)\n",
    "        return ant\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = 1\n",
    "        temp = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i])- ord(s[i-1]) == 1:\n",
    "                temp += 1\n",
    "            else:\n",
    "                ans = max(ans, temp)\n",
    "                temp = 1\n",
    "        return max(ans, temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = 1\n",
    "        cnt = 1\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i])-ord(s[i-1]) == 1:\n",
    "                cnt += 1\n",
    "                ans = max(ans,cnt)\n",
    "            else:\n",
    "                cnt = 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "        return max(ans, len(s) - start)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l =temp= 1\n",
    "        i = 0\n",
    "        while i<len(s)-1:\n",
    "            if  ord(s[i+1])-ord('a')== ord(s[i])+1-ord('a'):\n",
    "                temp+=1\n",
    "            else:\n",
    "                temp = 1\n",
    "            l=max(l,temp)\n",
    "            i+=1\n",
    "        return l\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "def max_(a, b):\n",
    "    return a if a > b else b\n",
    "\n",
    "\n",
    "def min_(a, b):\n",
    "    return a if a < b else b\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        ans = cnt = 0\n",
    "        pre = -2\n",
    "        for w in s:\n",
    "            i = ord(w) - ord(\"a\")\n",
    "            if i != pre+1:\n",
    "                ans = max_(ans, cnt)\n",
    "                pre = i\n",
    "                cnt = 1\n",
    "            else:\n",
    "                pre = i\n",
    "                cnt += 1\n",
    "        ans = max_(ans, cnt)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        l = r = 0\n",
    "        n = len(s)\n",
    "        ans = 1\n",
    "        while l<n :\n",
    "            while r <n and ord(s[r])==ord(s[l])+r-l :\n",
    "                r += 1\n",
    "            ans = max(ans,r-l)\n",
    "            l = r\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        res = 1\n",
    "        count = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) == ord(s[i-1]) + 1:\n",
    "                count += 1\n",
    "                if count > res:\n",
    "                    res = count\n",
    "            else:\n",
    "                count = 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        cur_l = max_l = 1\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i])-ord(s[i-1]) == 1:\n",
    "                cur_l += 1\n",
    "            else:\n",
    "                cur_l = 1\n",
    "            max_l = max(max_l,cur_l)\n",
    "        return max_l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans,start=0,0\n",
    "        for i in range(1,len(s)):\n",
    "            if ord(s[i])!=ord(s[i-1])+1:\n",
    "                ans=max(ans,i-start)\n",
    "                start=i\n",
    "        return max(ans,len(s)-start)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ret = cnt = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) == ord(s[i - 1]) + 1:\n",
    "                cnt += 1\n",
    "            else:\n",
    "                ret = max(ret, cnt)\n",
    "                cnt = 1\n",
    "        return max(ret, cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        left, right = 0, 1\n",
    "        result = 1\n",
    "        while(right < n):\n",
    "            if(ord(s[right]) - ord(s[right-1]) == 1):\n",
    "                right += 1\n",
    "            else:\n",
    "                result = max(result, right-left)\n",
    "                left = right\n",
    "                right += 1\n",
    "            if(result == 26):\n",
    "                return 26\n",
    "        result = max(result, right-left)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "        return max(ans, len(s) - start)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans, k, tmp = 1, 1, s[0]\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) == ord(tmp) + 1:\n",
    "                k += 1\n",
    "            else:\n",
    "                k = 1\n",
    "            tmp = s[i]\n",
    "            ans = max(ans, k)\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        max_len = 0\n",
    "        current_len = 0\n",
    "        prev_char = \"\"\n",
    "        \n",
    "        for char in s:\n",
    "            if prev_char == \"\":\n",
    "                current_len = 1\n",
    "            elif ord(char) - ord(prev_char) == 1:\n",
    "                current_len += 1\n",
    "            else:\n",
    "                current_len = 1\n",
    "            \n",
    "            max_len = max(max_len, current_len)\n",
    "            prev_char = char\n",
    "        \n",
    "        return max_len\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        left, right = 0, 1\n",
    "        result = 1\n",
    "        while(right < n):\n",
    "            if(ord(s[right]) - ord(s[right-1]) == 1):\n",
    "                right += 1\n",
    "            else:\n",
    "                result = max(result, right-left)\n",
    "                left = right\n",
    "                right += 1\n",
    "        result = max(result, right-left)\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        count = 1\n",
    "        count_max = count\n",
    "        for index in range(0, len(s)-1):\n",
    "            char = s[index]\n",
    "            char_next = s[index + 1]\n",
    "            print(char_next, chr(ord(char)+1))\n",
    "            if char_next == chr(ord(char)+1):\n",
    "                count += 1\n",
    "                if count > count_max: count_max = count\n",
    "            else:\n",
    "                count = 1\n",
    "        return count_max"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        res = 0\n",
    "\n",
    "        i = 0\n",
    "        while i < len(s):\n",
    "            start = i\n",
    "            while i < len(s) and (i == start or ord(s[i]) - ord(s[i - 1]) == 1):\n",
    "                i += 1\n",
    "            res = max(res, i - 1 - start + 1)\n",
    "        \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        res = 0\n",
    "        temp = 1\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) - ord(s[i - 1]) == 1:\n",
    "                temp += 1\n",
    "                continue\n",
    "            else:\n",
    "                res = max(res, temp)\n",
    "                temp = 1\n",
    "        res = max(res, temp)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    # # 模拟\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "\n",
    "        return max(ans, len(s) - start)\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "\n",
    "        # ans 维护最长的字母序连续字符串的长度\n",
    "        ans: int = 0\n",
    "        # cnt 表示当前字母序连续字符串的长度，\n",
    "        # 初始为字母序连续字符串仅由第一个字母组成，长度为 1\n",
    "        cnt: int = 1\n",
    "        # 遍历 s 中的每个字母\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i - 1]) + 1 == ord(s[i]):\n",
    "                # 如果是连续的字母，则字母序连续字符串的长度 +1\n",
    "                cnt += 1\n",
    "            else:\n",
    "                # 如果不是连续的字母，则先更新 ans 的最大值\n",
    "                ans = max(ans, cnt)\n",
    "                # 再以当前字母为新的字母序连续字符串，长度为 1\n",
    "                cnt = 1\n",
    "\n",
    "        # 注意要计入最后一个字母序连续字符串的长度\n",
    "        return max(ans, cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans = start = 0\n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) != ord(s[i - 1]) + 1:\n",
    "                ans = max(ans, i - start)\n",
    "                start = i  # 新起点\n",
    "        return max(ans, len(s) - start)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        max_length = 1\n",
    "        current_length = 1\n",
    "        \n",
    "        for i in range(1, len(s)):\n",
    "            if ord(s[i]) == ord(s[i-1]) + 1:\n",
    "                current_length += 1\n",
    "            else:\n",
    "                max_length = max(max_length, current_length)\n",
    "                current_length = 1\n",
    "                \n",
    "        return max(max_length, current_length)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        ans=0\n",
    "        n=len(s)\n",
    "        i=0\n",
    "        while i<n:\n",
    "            j=i+1\n",
    "            while j<n and ord(s[j])==ord(s[j-1])+1:\n",
    "                j+=1\n",
    "            ans=max(ans,j-i)\n",
    "            i=j\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        if len(s)<2: return len(s)\n",
    "        best = 0\n",
    "        n = len(s)\n",
    "        i = 0\n",
    "        for k in range(1,n):\n",
    "            if ord(s[k])-ord(s[k-1])==1:\n",
    "                continue\n",
    "            else:\n",
    "                if k-i>best:\n",
    "                    ans = s[i:k]\n",
    "                    best = k - i\n",
    "                i = k\n",
    "        if k-i>best:\n",
    "            ans = s[i:]\n",
    "        return len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\r\n",
    "        res = 1\r\n",
    "        cur = 1\r\n",
    "        for i in range(1, len(s)):\r\n",
    "            if ord(s[i]) == ord(s[i - 1]) + 1:\r\n",
    "                cur += 1\r\n",
    "                res = max(res, cur)\r\n",
    "            else:\r\n",
    "                cur = 1\r\n",
    "        return res\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "\n",
    "        out=1\n",
    "        m=0\n",
    "        lis=[]\n",
    "        for i in range(len(s)):\n",
    "            #print(ord(s[i]))\n",
    "            if m+1==ord(s[i]):\n",
    "                out=out+1\n",
    "            else:\n",
    "                lis.append(out)\n",
    "                out=1\n",
    "            m=ord(s[i])\n",
    "        lis.append(out)\n",
    "        #print(lis)\n",
    "        return(max(lis))\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n=len(s)\n",
    "        dp=[1]*n\n",
    "\n",
    "        ans=1\n",
    "        for i in range(1, n):\n",
    "            if ord(s[i-1])+1==ord(s[i]):\n",
    "                dp[i]=dp[i-1]+1\n",
    "                ans=max(ans, dp[i])\n",
    "\n",
    "        return ans\n",
    "        \n",
    "\n",
    "        \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        target = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "        ans = 0\n",
    "        n = len(s)\n",
    "        f = [0]*(n)\n",
    "        for i in range(n):\n",
    "            for j in range(26):\n",
    "                if s[i] == target[j]:\n",
    "                    if j>0 and i>0:\n",
    "                        f[i] = f[i-1]+1 if s[i-1]== target[j-1] else 1\n",
    "                    else:\n",
    "                        f[i] = 1\n",
    "        return max(f)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def longestContinuousSubstring(self, s: str) -> int:\n",
    "        n = len(s)\n",
    "        dp = [None] * n\n",
    "        dp[0] = 1\n",
    "        for i in range(1, n):\n",
    "            if ord(s[i]) - ord(s[i-1]) == 1:\n",
    "                dp[i] = dp[i-1] + 1\n",
    "            else:\n",
    "                dp[i] = 1\n",
    "        return max(dp)\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
